<!DOCTYPE html>
<html lang=zh>
<head>
  <meta charset="utf-8">
  
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-transform" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no,email=no,adress=no">
  <!-- Color theme for statusbar -->
  <meta name="theme-color" content="#000000" />
  <!-- 强制页面在当前窗口以独立页面显示,防止别人在框架里调用页面 -->
  <meta http-equiv="window-target" content="_top" />
  
  
  <title>Git 日常工作流程 | 知识是最有价值的东西</title>
  <meta name="description" content="Git日常工作  查看分支状态 查看分支状态，查看本地是否有修改或未提交的文件  git status  提交本地修改 当本地有修改和未提交的时候，在我们开发时建议尽量保持团队代码最新更新，及时提交每天的更新  # 添加所有修改和添加文件，也可以添加指定文件git add .# 添加指定文件git add test.txt# 提交修改git commit -m &quot;备注信息&quot;">
<meta property="og:type" content="article">
<meta property="og:title" content="Git 日常工作流程">
<meta property="og:url" content="http:&#x2F;&#x2F;jirenyou.gitee.io&#x2F;blog&#x2F;2019&#x2F;12&#x2F;21&#x2F;git&#x2F;git-common&#x2F;index.html">
<meta property="og:site_name" content="知识是最有价值的东西">
<meta property="og:description" content="Git日常工作  查看分支状态 查看分支状态，查看本地是否有修改或未提交的文件  git status  提交本地修改 当本地有修改和未提交的时候，在我们开发时建议尽量保持团队代码最新更新，及时提交每天的更新  # 添加所有修改和添加文件，也可以添加指定文件git add .# 添加指定文件git add test.txt# 提交修改git commit -m &quot;备注信息&quot;">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2019-12-21T08:24:15.000Z">
<meta property="article:modified_time" content="2019-12-21T08:24:15.000Z">
<meta property="article:author" content="Jirry">
<meta property="article:tag" content="git">
<meta name="twitter:card" content="summary">
  <!-- Canonical links -->
  <link rel="canonical" href="http://jirenyou.gitee.io/blog/2019/12/21/git/git-common/index.html">
  
    <link rel="alternate" href="/atom.xml" title="知识是最有价值的东西" type="application/atom+xml">
  
  
    <link rel="icon" href="/blog/favicon.ico" type="image/x-icon">
  
  
<link rel="stylesheet" href="/blog/css/style.css">

  
  
  
  
<meta name="generator" content="Hexo 4.1.0"></head>


<body class="main-center theme-black" itemscope itemtype="http://schema.org/WebPage">
  <header class="header" itemscope itemtype="http://schema.org/WPHeader">
  <div class="slimContent">
    <div class="navbar-header">
      
      
      <div class="profile-block text-center">
        <a id="avatar" href="https://jirenyou.gitee.io/blog" target="_blank">
          <img class="img-circle img-rotate" src="/blog/images/avatar.jpg" width="200" height="200">
        </a>
        <h2 id="name" class="hidden-xs hidden-sm">Jirry</h2>
        <h3 id="title" class="hidden-xs hidden-sm hidden-md">Back end development Architecture</h3>
        <small id="location" class="text-muted hidden-xs hidden-sm"><i class="icon icon-map-marker"></i> Shenzhen, China</small>
      </div>
      
      <div class="search" id="search-form-wrap">

    <form class="search-form sidebar-form">
        <div class="input-group">
            <input type="text" class="search-form-input form-control" placeholder="搜索" />
            <span class="input-group-btn">
                <button type="submit" class="search-form-submit btn btn-flat" onclick="return false;"><i class="icon icon-search"></i></button>
            </span>
        </div>
    </form>
    <div class="ins-search">
  <div class="ins-search-mask"></div>
  <div class="ins-search-container">
    <div class="ins-input-wrapper">
      <input type="text" class="ins-search-input" placeholder="想要查找什么..." x-webkit-speech />
      <button type="button" class="close ins-close ins-selectable" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
    </div>
    <div class="ins-section-wrapper">
      <div class="ins-section-container"></div>
    </div>
  </div>
</div>


</div>
      <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <nav id="main-navbar" class="collapse navbar-collapse" itemscope itemtype="http://schema.org/SiteNavigationElement" role="navigation">
      <ul class="nav navbar-nav main-nav ">
        
        
        <li class="menu-item menu-item-home">
          <a href="/blog/.">
            
            <i class="icon icon-home-fill"></i>
            
            <span class="menu-title">首页</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives">
            
            <i class="icon icon-archives-fill"></i>
            
            <span class="menu-title">归档</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories">
            
            <i class="icon icon-folder"></i>
            
            <span class="menu-title">分类</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags">
            
            <i class="icon icon-tags"></i>
            
            <span class="menu-title">标签</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-repository">
          <a href="/blog/repository">
            
            <i class="icon icon-project"></i>
            
            <span class="menu-title">项目</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-links">
          <a href="/blog/links">
            
            <i class="icon icon-friendship"></i>
            
            <span class="menu-title">友链</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-about">
          <a href="/blog/about">
            
            <i class="icon icon-cup-fill"></i>
            
            <span class="menu-title">关于</span>
          </a>
        </li>
        
      </ul>
      
	
    <ul class="social-links">
    	
        <li><a href="https://github.com/jirryji" target="_blank" title="Github" data-toggle=tooltip data-placement=top><i class="icon icon-github"></i></a></li>
        
        <li><a href="https://weibo.com/7355950025" target="_blank" title="Weibo" data-toggle=tooltip data-placement=top><i class="icon icon-weibo"></i></a></li>
        
        <li><a href="/blog/atom.xml" target="_blank" title="Rss" data-toggle=tooltip data-placement=top><i class="icon icon-rss"></i></a></li>
        
    </ul>

    </nav>
  </div>
</header>

  
    <aside class="sidebar" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    
      <div class="widget">
    <h3 class="widget-title">公告</h3>
    <div class="widget-body">
        <div id="board">
            <div class="content">
                <p>欢迎交流与分享经验!</p>
            </div>
        </div>
    </div>
</div>

    
      
  <div class="widget">
    <h3 class="widget-title">分类</h3>
    <div class="widget-body">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/docker/">docker</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/elasticsearch/">elasticsearch</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/java/">java</a><span class="category-list-count">9</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/php/">php</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/">版本控制</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E8%AF%AD%E6%B3%95/">语法</a><span class="category-list-count">1</span><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E8%AF%AD%E6%B3%95/markdown-%E8%AF%AD%E6%B3%95/">markdown 语法</a><span class="category-list-count">1</span></li></ul></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签</h3>
    <div class="widget-body">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/aop/" rel="tag">aop</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/bloom-filter/" rel="tag">bloom-filter</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/busybox/" rel="tag">busybox</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/docker/" rel="tag">docker</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/elasticsearch/" rel="tag">elasticsearch</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/es/" rel="tag">es</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/filter/" rel="tag">filter</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/git/" rel="tag">git</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/hashMap/" rel="tag">hashMap</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/idea/" rel="tag">idea</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/interceptor/" rel="tag">interceptor</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/iterator/" rel="tag">iterator</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/java/" rel="tag">java</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/localDateTime/" rel="tag">localDateTime</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/map/" rel="tag">map</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/markdown/" rel="tag">markdown</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/maven/" rel="tag">maven</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/redis/" rel="tag">redis</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/redis-lua%E8%84%9A%E6%9C%AC/" rel="tag">redis lua脚本</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/volumes/" rel="tag">volumes</a><span class="tag-list-count">1</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签云</h3>
    <div class="widget-body tagcloud">
      <a href="/blog/tags/aop/" style="font-size: 13px;">aop</a> <a href="/blog/tags/bloom-filter/" style="font-size: 13px;">bloom-filter</a> <a href="/blog/tags/busybox/" style="font-size: 13px;">busybox</a> <a href="/blog/tags/docker/" style="font-size: 14px;">docker</a> <a href="/blog/tags/elasticsearch/" style="font-size: 13.67px;">elasticsearch</a> <a href="/blog/tags/es/" style="font-size: 13px;">es</a> <a href="/blog/tags/filter/" style="font-size: 13.33px;">filter</a> <a href="/blog/tags/git/" style="font-size: 13.33px;">git</a> <a href="/blog/tags/hashMap/" style="font-size: 13px;">hashMap</a> <a href="/blog/tags/idea/" style="font-size: 13px;">idea</a> <a href="/blog/tags/interceptor/" style="font-size: 13px;">interceptor</a> <a href="/blog/tags/iterator/" style="font-size: 13px;">iterator</a> <a href="/blog/tags/java/" style="font-size: 13.67px;">java</a> <a href="/blog/tags/localDateTime/" style="font-size: 13px;">localDateTime</a> <a href="/blog/tags/map/" style="font-size: 13px;">map</a> <a href="/blog/tags/markdown/" style="font-size: 13px;">markdown</a> <a href="/blog/tags/maven/" style="font-size: 13.67px;">maven</a> <a href="/blog/tags/redis/" style="font-size: 13px;">redis</a> <a href="/blog/tags/redis-lua%E8%84%9A%E6%9C%AC/" style="font-size: 13px;">redis lua脚本</a> <a href="/blog/tags/volumes/" style="font-size: 13px;">volumes</a>
    </div>
  </div>

    
      
  <div class="widget">
    <h3 class="widget-title">归档</h3>
    <div class="widget-body">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/01/">一月 2020</a><span class="archive-list-count">9</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2019/12/">十二月 2019</a><span class="archive-list-count">11</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget-body">
      <ul class="recent-post-list list-unstyled no-thumbnail">
        
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/java/">java</a>
              </p>
              <p class="item-title">
                <a href="/blog/2020/01/14/java/maven/mvn-private-repo/" class="title">Maven私服（Nexus）搭建</a>
              </p>
              <p class="item-date">
                <time datetime="2020-01-14T13:37:39.000Z" itemprop="datePublished">2020-01-14</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/java/">java</a>
              </p>
              <p class="item-title">
                <a href="/blog/2020/01/09/java/java-idea-start-slow/" class="title">解决Idea启动Spring Boot很慢的问题</a>
              </p>
              <p class="item-date">
                <time datetime="2020-01-09T15:24:15.000Z" itemprop="datePublished">2020-01-09</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/java/">java</a>
              </p>
              <p class="item-title">
                <a href="/blog/2020/01/09/java/java-springboot-filter-in-aop/" class="title">AOP（面向切面编程）、Filter（过虑器）、Interceptor（拦截器）</a>
              </p>
              <p class="item-date">
                <time datetime="2020-01-09T15:24:15.000Z" itemprop="datePublished">2020-01-09</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/java/">java</a>
              </p>
              <p class="item-title">
                <a href="/blog/2020/01/09/java/java-req-resp/" class="title">HttpServletRequest 与 HttpServletResponse 的实现类</a>
              </p>
              <p class="item-date">
                <time datetime="2020-01-09T08:24:15.000Z" itemprop="datePublished">2020-01-09</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/java/">java</a>
              </p>
              <p class="item-title">
                <a href="/blog/2020/01/09/java/java-springboot-filter/" class="title">Spring Boot 过滤器 Filter</a>
              </p>
              <p class="item-date">
                <time datetime="2020-01-09T08:24:15.000Z" itemprop="datePublished">2020-01-09</time>
              </p>
            </div>
          </li>
          
      </ul>
    </div>
  </div>
  

    
  </div>
</aside>

  
  
<aside class="sidebar sidebar-toc collapse" id="collapseToc" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    <nav id="toc" class="article-toc">
      <h3 class="toc-title">文章目录</h3>
      <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#查看分支状态"><span class="toc-number">1.</span> <span class="toc-text">查看分支状态</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#提交本地修改"><span class="toc-number">2.</span> <span class="toc-text">提交本地修改</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#推送分支"><span class="toc-number">3.</span> <span class="toc-text">推送分支</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#拉取分支最新提交"><span class="toc-number">4.</span> <span class="toc-text">拉取分支最新提交</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#储藏工作区"><span class="toc-number">5.</span> <span class="toc-text">储藏工作区</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#合并多个提交为一个提交"><span class="toc-number">6.</span> <span class="toc-text">合并多个提交为一个提交</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#丢弃修改"><span class="toc-number">7.</span> <span class="toc-text">丢弃修改</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#版本回退"><span class="toc-number">8.</span> <span class="toc-text">版本回退</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#提交回滚"><span class="toc-number">9.</span> <span class="toc-text">提交回滚</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#远程分支"><span class="toc-number">10.</span> <span class="toc-text">远程分支</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#查看远程分支"><span class="toc-number">10.1.</span> <span class="toc-text">查看远程分支</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#删除远程分支"><span class="toc-number">10.2.</span> <span class="toc-text">删除远程分支</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#标签"><span class="toc-number">11.</span> <span class="toc-text">标签</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#标签相关命令"><span class="toc-number">11.1.</span> <span class="toc-text">标签相关命令</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#打标签"><span class="toc-number">11.2.</span> <span class="toc-text">打标签</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#提取标签"><span class="toc-number">11.3.</span> <span class="toc-text">提取标签</span></a></li></ol></li></ol>
    </nav>
  </div>
</aside>

<main class="main" role="main">
  <div class="content">
  <article id="post-git/git-common" class="article article-type-post" itemscope itemtype="http://schema.org/BlogPosting">
    
    <div class="article-header">
      
        
  
    <h1 class="article-title" itemprop="name">
      Git 日常工作流程
    </h1>
  

      
      <div class="article-meta">
        <span class="article-date">
    <i class="icon icon-calendar-check"></i>
	<a href="/blog/2019/12/21/git/git-common/" class="article-date">
	  <time datetime="2019-12-21T08:24:15.000Z" itemprop="datePublished">2019-12-21</time>
	</a>
</span>
        
  <span class="article-category">
    <i class="icon icon-folder"></i>
    <a class="article-category-link" href="/blog/categories/%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/">版本控制</a>
  </span>

        
  <span class="article-tag">
    <i class="icon icon-tags"></i>
	<a class="article-tag-link" href="/blog/tags/git/" rel="tag">git</a>
  </span>


        
	<span class="article-read hidden-xs">
	    <i class="icon icon-eye-fill" aria-hidden="true"></i>
	    <span id="busuanzi_container_page_pv">
			<span id="busuanzi_value_page_pv">0</span>
		</span>
	</span>


        <span class="post-comment"><i class="icon icon-comment"></i> <a href="/blog/2019/12/21/git/git-common/#comments" class="article-comment-link">评论</a></span>
        
	
	

      </div>
    </div>
    <div class="article-entry marked-body" itemprop="articleBody">
      
        <blockquote>
<p>Git日常工作</p>
</blockquote>
<h2 id="查看分支状态"><a href="#查看分支状态" class="headerlink" title="查看分支状态"></a>查看分支状态</h2><blockquote>
<p>查看分支状态，查看本地是否有修改或未提交的文件</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">git status</span></pre></td></tr></table></figure>

<h2 id="提交本地修改"><a href="#提交本地修改" class="headerlink" title="提交本地修改"></a>提交本地修改</h2><blockquote>
<p>当本地有修改和未提交的时候，在我们开发时建议尽量保持团队代码最新更新，及时提交每天的更新</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line"># 添加所有修改和添加文件，也可以添加指定文件</span></pre></td></tr><tr><td class="code"><pre><span class="line">git add .</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line"># 添加指定文件</span></pre></td></tr><tr><td class="code"><pre><span class="line">git add test.txt</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line"># 提交修改</span></pre></td></tr><tr><td class="code"><pre><span class="line">git commit -m &quot;备注信息&quot;</span></pre></td></tr></table></figure>

<h2 id="推送分支"><a href="#推送分支" class="headerlink" title="推送分支"></a>推送分支</h2><blockquote>
<p>及时推送本地提交</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line"># 推送当前分支到已关联远程分支，如果本地分支未与远程分支关联先关联远程分支或指定推送分支</span></pre></td></tr><tr><td class="code"><pre><span class="line">git push</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line"># 推送当前分支到远程 master 分支</span></pre></td></tr><tr><td class="code"><pre><span class="line">git push origin master </span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line"># 关联当前分支到远程 master 分支</span></pre></td></tr><tr><td class="code"><pre><span class="line">git push --set-upstream origin master</span></pre></td></tr></table></figure>

<h2 id="拉取分支最新提交"><a href="#拉取分支最新提交" class="headerlink" title="拉取分支最新提交"></a>拉取分支最新提交</h2><blockquote>
<p>当远程分支有其他人提交了代码，这个时候我们的提交是推送不上去的，需要先拉取最新提交合并到本地后才能推送我们的提交</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line"># 拉取最新更新并立即合并</span></pre></td></tr><tr><td class="code"><pre><span class="line">git pull</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line"># 拉取最新更新使用变基方式代替合并</span></pre></td></tr><tr><td class="code"><pre><span class="line">git pull --rebase</span></pre></td></tr></table></figure>

<h2 id="储藏工作区"><a href="#储藏工作区" class="headerlink" title="储藏工作区"></a>储藏工作区</h2><blockquote>
<p>当正在dev分支上开发某个项目，这时项目中出现一个bug，需要紧急修复，但是正在开发的内容只是完成一半，还不想提交，或本应该在dev分支开发的代码，不小心在其他分支上开发了，这时可以用git stash命令将修改的内容保存至堆栈区，然后切换到hotfix分支进行bug修复，修复完成后，再切回到dev分支，从堆栈中恢复刚刚保存的内容</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line"># 查看储藏列表</span></pre></td></tr><tr><td class="code"><pre><span class="line">git stash list</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line"># 查看储藏明细(x为储藏索引)，如果不指定 stash@&#123;x&#125; 则显示最新储藏明细</span></pre></td></tr><tr><td class="code"><pre><span class="line"># -p 显示修改信息</span></pre></td></tr><tr><td class="code"><pre><span class="line">git stash show stash@&#123;x&#125; -p</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line"># 储藏当前工作区，并添加备注信息(备注信息可以不需要，但建议每个储藏都添加备注，以便后续查找和使用)</span></pre></td></tr><tr><td class="code"><pre><span class="line">git stash save &quot;v1.0-30%&quot;</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line"># 恢复指定储藏到工作区并删除储藏；pop：弹出并删除储藏</span></pre></td></tr><tr><td class="code"><pre><span class="line">git stash pop stash@&#123;x&#125;</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line"># 应用指定储藏到工作区</span></pre></td></tr><tr><td class="code"><pre><span class="line">git stash apply stash@&#123;x&#125;</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line"># 删除指定储藏</span></pre></td></tr><tr><td class="code"><pre><span class="line">git stash drop stash@&#123;x&#125;</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line"># 删除所有储藏</span></pre></td></tr><tr><td class="code"><pre><span class="line">git stash clean</span></pre></td></tr></table></figure>

<h2 id="合并多个提交为一个提交"><a href="#合并多个提交为一个提交" class="headerlink" title="合并多个提交为一个提交"></a>合并多个提交为一个提交</h2><blockquote>
<p>当我们在dev分支每天提交了很多次修改，开发完成后，需要将这次开发的功能遴选到其他分支，如提交到测试分支部署，那么这个时候我们就需要将多个提交的点合并成一个提交，然后遴选到另一个分支上去</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line"># 查看日志记录；找到本次开发第一个提交的记录，并复制第一个提交的上一次提交版本号</span></pre></td></tr><tr><td class="code"><pre><span class="line">git log --oneline</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line"># 变基；如：找到第一次提交的版本号是 aaa,上一次提交的版本号是 bbb</span></pre></td></tr><tr><td class="code"><pre><span class="line">git rebase -i bbb</span></pre></td></tr></table></figure>

<h2 id="丢弃修改"><a href="#丢弃修改" class="headerlink" title="丢弃修改"></a>丢弃修改</h2><blockquote>
<p>放弃修改操作</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line"># 丢弃所有未提交的修改</span></pre></td></tr><tr><td class="code"><pre><span class="line">git checkout . </span></pre></td></tr><tr><td class="code"><pre><span class="line">git checkout -- *</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line"># 丢弃某个未提交的文件修改</span></pre></td></tr><tr><td class="code"><pre><span class="line">git checkout -- 文件路径</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line"># 回退到上一个版本</span></pre></td></tr><tr><td class="code"><pre><span class="line">git reset --hard HEAD^</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line"># 回退到上上次版本</span></pre></td></tr><tr><td class="code"><pre><span class="line">git reset --hard HEAD^^</span></pre></td></tr><tr><td class="code"><pre><span class="line">git reset --hard HEAD^^^</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line"># 回退到指定commitid的版本</span></pre></td></tr><tr><td class="code"><pre><span class="line">git reset --hard commit_id</span></pre></td></tr></table></figure>

<h2 id="版本回退"><a href="#版本回退" class="headerlink" title="版本回退"></a>版本回退</h2><blockquote>
<p>当不小心将错误当代码推送到远程仓库想要回撤并且不留下版本记录时</p>
<p><strong>适用场景：</strong> 如果想恢复到之前某个提交的版本，且那个版本之后提交的版本我们都不要了，就可以用这种方法</p>
</blockquote>
<p><strong>步骤</strong></p>
<ol>
<li>选中要回撤到到版本，点击重置到这次提交（命令：<code>git reset --soft [commit_id]</code>），<strong>此时本地版本将会重置到该版本，并且落后于远程分支</strong></li>
<li>最后使用命令行强制推送，<strong>将本地代码强制覆盖到远程仓库</strong></li>
</ol>
<p><strong>命令</strong></p>
<ol>
<li>重置提交：<code>git reset [--soft|--hard] [commit_id]</code><ul>
<li><code>--soft</code>：该参数会将工作去的文件回退到目标版本，但是不会改变暂存区的状态</li>
<li><code>--hard</code>：该参数会直接删除掉目标HEAD之后所有的操作，且工作区和暂存区都会修改</li>
<li>commit_id：提交版本ID</li>
</ul>
</li>
<li>强制推送：<code>git push --force origin [branch_name]</code><ul>
<li>branch_name：分支名称</li>
</ul>
</li>
</ol>
<p><strong>示例</strong></p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 重置提交到 4956331</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">git reset --soft 4956331</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment"># 强制推送覆盖远程 dev 分支</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">git push --force origin dev</span></pre></td></tr></table></figure>



<h2 id="提交回滚"><a href="#提交回滚" class="headerlink" title="提交回滚"></a>提交回滚</h2><blockquote>
<p>希望将当前提交的版本回滚到这次提交之前并且保留这次提交，可以使用提交回滚</p>
<p><strong>适用场景：</strong> 如果我们想撤销之前的某一版本，但是又想保留该目标版本后面的版本，记录下这整个版本变动流程，就可以用这种方法</p>
</blockquote>
<p><strong>步骤</strong></p>
<ol>
<li>选中要回滚的版本，点击提交回滚，<strong>此时本地分支将会回滚到该提交之前到状态，回滚也会被当作一次提交，并且领先于远程分支</strong></li>
<li>最后推送代码即可完成远程仓库提交记录回滚，并且保留被回滚到记录</li>
</ol>
<p><strong>命令</strong></p>
<ol>
<li>回滚提交：<code>git revert -n [commit_id]</code><ul>
<li>commit_id：提交版本ID</li>
</ul>
</li>
<li>推送远程：<code>git push origin [branch_name]</code><ul>
<li>branch_name：分支名称</li>
</ul>
</li>
</ol>
<p><strong>示例</strong></p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr></table></figure>



<h2 id="远程分支"><a href="#远程分支" class="headerlink" title="远程分支"></a>远程分支</h2><h3 id="查看远程分支"><a href="#查看远程分支" class="headerlink" title="查看远程分支"></a>查看远程分支</h3><ul>
<li>拉取远程最新提交：<code>git pull</code></li>
<li>查看本地所有远程分支：<code>git branch -r</code></li>
</ul>
<h3 id="删除远程分支"><a href="#删除远程分支" class="headerlink" title="删除远程分支"></a>删除远程分支</h3><ul>
<li>删除本地远程分支：<code>git branch -r -d [远程分支名称]</code></li>
<li>推送到远程仓库：<code>git push origin :[分支名称]</code></li>
</ul>
<h2 id="标签"><a href="#标签" class="headerlink" title="标签"></a>标签</h2><h3 id="标签相关命令"><a href="#标签相关命令" class="headerlink" title="标签相关命令"></a>标签相关命令</h3><ul>
<li>查看所有标签：<code>git tag</code></li>
<li>显示标签名及描述信息：<code>git tag -ln [tag_name]</code></li>
<li>查看标签详细信息：<code>git show [tag_name]</code></li>
<li>当前commit创建标签：<code>git tag -a [tag_name] -m &quot;标签备注信息&quot;</code></li>
<li>指定commit创建标签：<code>git tag -a [tag_name] -m &quot;标签备注信息&quot; [commit_id]</code></li>
<li>推送本地标签到远程仓库：<code>git push [remote_name] [tag_name]</code></li>
<li>推送本地所有标签推送到远程仓库：<code>git push [remote_name] --tags</code></li>
<li>删除本地标签：<code>git tag -d [tag_name]</code></li>
<li>删除远程标签：<code>git push [remote_name] :refs/tags/[tag_name]</code></li>
</ul>
<h3 id="打标签"><a href="#打标签" class="headerlink" title="打标签"></a>打标签</h3><blockquote>
<p>通常在需求开发完成后，会将提交的多个点合并成一个点，然后发布，发布完成后会将发布的点遴选到master分支，并打上版本标签</p>
</blockquote>
<p><strong>步骤</strong></p>
<ul>
<li>查看本地标签信息：<code>git tag -ln</code></li>
<li>添加标签并备注信息：<code>git tag -a [tag_name] -m &quot;备注信息&quot;</code></li>
<li>推送标签到远程仓库：<code>git push [remote_name] [tag_name]</code></li>
</ul>
<h3 id="提取标签"><a href="#提取标签" class="headerlink" title="提取标签"></a>提取标签</h3><blockquote>
<p>提取为zip格式，输出路径可以是相对路径，也可以是绝对路径</p>
</blockquote>
<p><strong>命令：</strong>git archive –format=zip —output=[path]/[name].zip [tag_name]</p>
<ul>
<li>path：输出路径</li>
<li>name：输出名称</li>
<li>tag_name：标签名</li>
</ul>
<p><strong>示例：</strong>在d盘下生成包含0.8标签内容的压缩包</p>
<p><code>git archive --format=zip --output=d:/v0.8.zip v0.8</code></p>

      
    </div>
    <div class="article-footer">
      <blockquote class="mt-2x">
  <ul class="post-copyright list-unstyled">
    
    <li class="post-copyright-link hidden-xs">
      <strong>本文链接：</strong>
      <a href="http://jirenyou.gitee.io/blog/2019/12/21/git/git-common/" title="Git 日常工作流程" target="_blank" rel="external">http://jirenyou.gitee.io/blog/2019/12/21/git/git-common/</a>
    </li>
    
    <li class="post-copyright-license">
      <strong>版权声明： </strong> 本博客所有文章除特别声明外，均采用 <a href="http://creativecommons.org/licenses/by/4.0/deed.zh" target="_blank" rel="external">CC BY 4.0 CN协议</a> 许可协议。转载请注明出处！
    </li>
  </ul>
</blockquote>


<div class="panel panel-default panel-badger">
  <div class="panel-body">
    <figure class="media">
      <div class="media-left">
        <a href="https://jirenyou.gitee.io/blog" target="_blank" class="img-burn thumb-sm visible-lg">
          <img src="/blog/images/avatar.jpg" class="img-rounded w-full" alt="">
        </a>
      </div>
      <div class="media-body">
        <h3 class="media-heading"><a href="https://jirenyou.gitee.io/blog" target="_blank"><span class="text-dark">Jirry</span><small class="ml-1x">Back end development Architecture</small></a></h3>
        <div>后端开发攻城狮，热爱互联网技术，爱学习，勤思考！</div>
      </div>
    </figure>
  </div>
</div>


    </div>
  </article>
  
    
  <section id="comments">
  	
      <div id="vcomments"></div>
    
  </section>


  
</div>

  <nav class="bar bar-footer clearfix" data-stick-bottom>
  <div class="bar-inner">
  
  <ul class="pager pull-left">
    
    <li class="prev">
      <a href="/blog/2019/12/21/php/php-redis-lua/" title="使用 Redis Lua脚本设置和获取多维度数据缓存(PHP示例)"><i class="icon icon-angle-left" aria-hidden="true"></i><span>&nbsp;&nbsp;上一篇</span></a>
    </li>
    
    
    <li class="next">
      <a href="/blog/2019/12/19/java/java-localdatetime/" title="Java8 LocalDateTime 获取时间戳(秒、毫秒)，时间转换"><span>下一篇&nbsp;&nbsp;</span><i class="icon icon-angle-right" aria-hidden="true"></i></a>
    </li>
    
    
    <li class="toggle-toc">
      <a class="toggle-btn collapsed" data-toggle="collapse" href="#collapseToc" aria-expanded="false" title="文章目录" role="button">
        <span>[&nbsp;</span><span>文章目录</span>
        <i class="text-collapsed icon icon-anchor"></i>
        <i class="text-in icon icon-close"></i>
        <span>]</span>
      </a>
    </li>
    
  </ul>
  
  
  <!-- Button trigger modal -->
  <button type="button" class="btn btn-fancy btn-donate pop-onhover bg-gradient-warning" data-toggle="modal" data-target="#donateModal"><span>赏</span></button>
  <!-- <div class="wave-icon wave-icon-danger btn-donate" data-toggle="modal" data-target="#donateModal">
    <div class="wave-circle"><span class="icon"><i class="icon icon-bill"></i></span></div>
  </div> -->
  
  
  <div class="bar-right">
    
    <div class="share-component" data-sites="weibo,qq,wechat,facebook,twitter" data-mobile-sites="weibo,qq,qzone"></div>
    
  </div>
  </div>
</nav>
  
<!-- Modal -->
<div class="modal modal-center modal-small modal-xs-full fade" id="donateModal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content donate">
      <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
      <div class="modal-body">
        <div class="donate-box">
          <div class="donate-head">
            <p>感谢您的支持，我会继续努力的!</p>
          </div>
          <div class="tab-content">
            <div role="tabpanel" class="tab-pane fade active in" id="alipay">
              <div class="donate-payimg">
                <img src="/blog/images/donate/alipay.jpeg" alt="扫码支持" title="扫一扫" />
              </div>
              <p class="text-muted mv">扫码打赏，你说多少就多少</p>
              <p class="text-grey">打开支付宝扫一扫，即可进行扫码打赏哦</p>
            </div>
            <div role="tabpanel" class="tab-pane fade" id="wechatpay">
              <div class="donate-payimg">
                <img src="/blog/images/donate/wechat.jpeg" alt="扫码支持" title="扫一扫" />
              </div>
              <p class="text-muted mv">扫码打赏，你说多少就多少</p>
              <p class="text-grey">打开微信扫一扫，即可进行扫码打赏哦</p>
            </div>
          </div>
          <div class="donate-footer">
            <ul class="nav nav-tabs nav-justified" role="tablist">
              <li role="presentation" class="active">
                <a href="#alipay" id="alipay-tab" role="tab" data-toggle="tab" aria-controls="alipay" aria-expanded="true"><i class="icon icon-alipay"></i> 支付宝</a>
              </li>
              <li role="presentation" class="">
                <a href="#wechatpay" role="tab" id="wechatpay-tab" data-toggle="tab" aria-controls="wechatpay" aria-expanded="false"><i class="icon icon-wepay"></i> 微信支付</a>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>



</main>

  <footer class="footer" itemscope itemtype="http://schema.org/WPFooter">
	
	
    <ul class="social-links">
    	
        <li><a href="https://github.com/jirryji" target="_blank" title="Github" data-toggle=tooltip data-placement=top><i class="icon icon-github"></i></a></li>
        
        <li><a href="https://weibo.com/7355950025" target="_blank" title="Weibo" data-toggle=tooltip data-placement=top><i class="icon icon-weibo"></i></a></li>
        
        <li><a href="/blog/atom.xml" target="_blank" title="Rss" data-toggle=tooltip data-placement=top><i class="icon icon-rss"></i></a></li>
        
    </ul>

    <div class="copyright">
    	
        &copy; 2020 Jirry
        
        <div class="publishby">
        	Theme by <a href="https://github.com/cofess" target="_blank"> cofess </a>base on <a href="https://github.com/cofess/hexo-theme-pure" target="_blank">pure</a>.
        </div>
    </div>
</footer>
  <script src="//cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<script>
window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
</script>

<script src="/blog/js/plugin.min.js"></script>


<script src="/blog/js/application.js"></script>


    <script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(未命名)',
        },
        ROOT_URL: '/blog/',
        CONTENT_URL: '/blog/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>

<script src="/blog/js/insight.js"></script>






   
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>





   
    
  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/valine"></script>
  <script type="text/javascript">
  var GUEST = ['nick', 'mail', 'link'];
  var meta = 'nick,mail,link';
  meta = meta.split(',').filter(function(item) {
    return GUEST.indexOf(item) > -1;
  });
  new Valine({
    el: '#vcomments',
    verify: false,
    notify: false,
    appId: '',
    appKey: '',
    placeholder: 'Just go go',
    avatar: 'mm',
    meta: meta,
    pageSize: '10' || 10,
    visitor: false
  });
  </script>

     







</body>
</html>